from rCube import RCube

class FlipBlock(RCube):
    
    def __init__(self):
        RCube.__init__(self)
        
        self.flipCount  = -1
        self.solidState = True
        self.setVar("flipTime", 3)
        self.setVar("grav", 0)
        self.setVar("base", "flipBlock")
        self.flipStandby = False
        self.flip = False
        
    def update(self, cmd, args):
        RCube.update(self, cmd, args)
    
        dt = args["dtime"]
        
        if(self.flipCount > -10):
            self.flipCount -= dt
        
        if(not (self.solidState) and (self.flipCount < 0)):
            self.solidState = True
            self.setVar("sides",['s','s','s','s'])
            self.setVar("shown", True)
            
        if(self.flip):
            self.flip = False
            self.solidState = False
            self.flipCount = self.getVar("flipTime")
            self.setVar("sides",['t','t','t','t'])
            self.setVar("shown", False)
            
        if(self.flipStandby):
            self.flipStandby = False
            self.flip = True
        
    def onCollision(self, dist, vec, side, sideType, above, toward, ignoreSurface, object):
        if(side == 1):
            objectBase = object.getVar('base')
            if(objectBase == "player"):
                if(self.solidState == True):
                    self.flipStandby = True